package framework 
{
	import joystick.JoystickState;
	
	/**
	 * ...
	 * @author omega
	 */
	public class Pad
	{
		private var keyPad:KeyPad;
		public var joystickState:JoystickState;
		
		public function Pad() 
		{
		}
		
		public function setKeyPad(k:KeyPad):void {
			keyPad = k;
		}
		public function setJoystickState(j:JoystickState):void {
			joystickState = j;
		}
		
		public function isPress(index:uint):Boolean {
			if (joystickState == null) {
				return keyPad.isPress(index) == true;
			}else{
				return (joystickState.isHeld(index) == true || keyPad.isPress(index) == true);
			}
		}
		
		public function isPush(index:uint):Boolean {
			if (joystickState == null) {
				return keyPad.isPush(index) == true;
			}else{
				return (joystickState.isDown(index) == true || keyPad.isPush(index) == true);
			}
		}
		
		public function getX():int {
			if (joystickState == null) {
				return keyPad.getX();
			}else {
				var x:int = joystickState.x + keyPad.getX();
				return Math.min(1, Math.max( -1, x));
			}
		}
		
		public function getY():int {
			if (joystickState == null) {
				return keyPad.getY();
			}else {
				var y:int = joystickState.y + keyPad.getY();
				return Math.min(1, Math.max( -1, y));
			}
		}
	}
}